package com.geeksx.trainer.controller;

import com.geeksx.trainer.common.api.Result;
import com.geeksx.trainer.entity.request.PracticeStartRequest;
import com.geeksx.trainer.entity.request.PracticeSubmitRequest;
import com.geeksx.trainer.entity.vo.QuestionVO;
import com.geeksx.trainer.service.PracticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 答题练习控制器
 */
@RestController
@RequestMapping("/api/practice")
@RequiredArgsConstructor
public class PracticeController {

    private final PracticeService practiceService;

    /**
     * 开始答题：根据学习模式和题型获取题目列表
     */
    @PostMapping("/start")
    public Result<List<QuestionVO>> startPractice(@RequestBody PracticeStartRequest request) {
        return Result.success(practiceService.startPractice(request));
    }

    /**
     * 获取智能推荐题目
     */
    @GetMapping("/recommend")
    public Result<QuestionVO> getRecommendQuestion(PracticeStartRequest request){
        return Result.success(practiceService.getRecommendQuestion(request));
    }

    /**
     * 提交答案
     */
    @PostMapping("/submit")
    public Result<Map<String, Object>> submitAnswer(@RequestBody PracticeSubmitRequest request) {
        return Result.success(practiceService.submitAnswer(request));
    }

    /**
     * 查询用户答题历史
     */
    @GetMapping("/history")
    public Result<Map<String, Object>> getHistory(
            @RequestParam Long userId,
            @RequestParam Long studyModeId) {
        return Result.success(practiceService.getHistory(userId, studyModeId));
    }
}
